﻿package glam.skins;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.Sprite;
import flash.Lib;
import fpc.styles.skins.IPanelSkin;
import fpc.styles.skins.NullPanelSkin;
import fpc.utils.IFactory;
import fpc.utils.ScaledBitmap;
import glam.Primitives;

class GlamPanel implements IFactory<IPanelSkin>
{	
	var _knockout:BitmapData;
	
	var _striae:BitmapData;
	
	public function new(primitives:Primitives = null)
	{
		if (primitives == null)
		{
			primitives = Primitives.defaultPrimitives;
		}
		_knockout = primitives.getKnockoutShape();
		_striae = primitives.getPanelStriae();
	}
	
	public function create():IPanelSkin
	{
		return new GlamPanelSkin(_striae, _knockout);
	}
}

class GlamPanelSkin implements IPanelSkin
{	
	var _scaled:ScaledBitmap;
	
	var _striaeBitmapData:BitmapData;
	
	var _sprite:Sprite;
	
	var _shape:Shape;
	
	public function new(striaeBitmapdData:BitmapData, knockoutBitmapData:BitmapData)
	{
		_sprite = new Sprite();
		_shape = new Shape();
		_sprite.addChild(_shape);
		object = _sprite;
		
		_striaeBitmapData = striaeBitmapdData;
		_scaled = new ScaledBitmap(_shape.graphics, knockoutBitmapData);
	}
	
	public function setSize(width:Int, height:Int)
	{
		var g = _sprite.graphics;
		g.clear();
		g.beginBitmapFill(_striaeBitmapData);
		g.drawRoundRect(3, 3, width - 6, height - 6, 4);
		g.endFill();
		_scaled.setBounds(0, 0, width, height);
	}
	
	public var object(default, null):DisplayObject;
}